home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / clang / c_course.zip / READLINE.C < prev    next >
C/C++ Source or Header  |  1989-12-30  |  795b  |  28 lines

  1. /*    READLINE.C   fgets()     do/while with test for NULL in loop  */
  2.  
  3. /*  fgets() gets a whole line, or rather gets characters until it sees an
  4. EOL or until it gets the number of charcters given in second of three 
  5. parameters.
  6. Like fscanf, the whole function takes on the value of the character stream
  7. as it fills its (first parameter) array.  That way if a NULL is read
  8. you can detect it in a conditional.     */
  9.  
  10. #include "stdio.h"
  11.  
  12. main()
  13. {
  14. FILE *fp1;
  15. char oneword[100];
  16. char *c;
  17.  
  18.    fp1 = fopen("TENLINES.TXT","r");
  19.  
  20.    do {
  21.       c = fgets(oneword,100,fp1); /* get one line from the file */
  22.       if (c != NULL)
  23.          printf("%s",oneword);    /* display it on the monitor  */
  24.    } while (c != NULL);          /* repeat until NULL          */
  25.  
  26.    fclose(fp1);
  27. }
  28.